package com.orangelife.mobile.main.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.android.util.ImageDownloader;
import com.curry.android.util.ImageDownloader.ImageSize;
import com.curry.orangelife.mobile.R;

import java.util.List;
import java.util.Map;

public class GoodsRentOrderListChildrenAdapter<T> extends FatherAdapter<T> {
	private Context context;
	private List<Map<String, Object>> list;

	private ImageDownloader image = ImageDownloader.getImageDownloader();
	public GoodsRentOrderListChildrenAdapter(Context context,
											 List<Map<String, Object>> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_goodsrent_order_children, null);
			viewHolder.ivMyGoodsPic = (ImageView) convertView
					.findViewById(R.id.ivMyGoodsPic);
			viewHolder.tvGoodsTitle = (TextView) convertView
					.findViewById(R.id.tvGoodsTitle);
			viewHolder.tvGoodsNum = (TextView) convertView
					.findViewById(R.id.tvGoodsNum2);
			viewHolder.tvPrice = (TextView) convertView
					.findViewById(R.id.tvPrice);
			viewHolder.tvFormerPrice = (TextView) convertView
					.findViewById(R.id.tvFormerPrice);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}


		Map<String, Object> map = list.get(position);
//		Map<String,Object> goodsMap = (Map<String, Object>) map.get("snap");
		image.download(map.get("goodsLogo").toString(),
				viewHolder.ivMyGoodsPic,
				ImageSize.IMAGE_SIZE_EXTRA_SMALL_RECTANGLE_JPG);
		viewHolder.tvGoodsTitle.setText(map.get("goodsName")
				.toString());
		viewHolder.tvGoodsNum.setText(map.get("days")
				.toString());
			viewHolder.tvPrice.setText("¥" + map.get("price").toString());
		viewHolder.tvFormerPrice.setText("¥" + map.get("price").toString());
		viewHolder.tvFormerPrice.getPaint().setFlags(
				Paint.STRIKE_THRU_TEXT_FLAG);
		viewHolder.tvFormerPrice.setVisibility(View.GONE);

		return convertView;

	}

	class ViewHolder {
		private ImageView ivMyGoodsPic;
		private TextView tvGoodsTitle;
		private TextView tvGoodsNum;
		private TextView tvFormerPrice;
		private TextView tvPrice;
	}

	@Override
	public BaseAdapter setList(List<T> list) {
		this.list = (List<Map<String, Object>>) list;
		return GoodsRentOrderListChildrenAdapter.this;
	}

}
